package com.kgc.community.service.impl;

import com.kgc.community.mapper.CostCountMapper;
import com.kgc.community.pojo.CostCount;
import com.kgc.community.pojo.CostCountExample;
import com.kgc.community.service.CostCountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author Mr.Man
 * @Date 2020-11-29 15:56
 **/
@Service
public class CostCountServiceImpl implements CostCountService {
    @Resource
    CostCountMapper costCountMapper;

    @Override
    public Integer deleteById(Integer id) {
        int i = costCountMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public List<CostCount> selectBy(String type, String descri) {
        CostCountExample costCountExample = new CostCountExample();

        if(type!=null&&type!=""&&type!="0"){
            costCountExample.createCriteria().andCostTypeIdEqualTo(Integer.parseInt(type));
        }
        if(descri!=null&&descri!=""){
            descri="%"+descri+"%";
            costCountExample.createCriteria().andDespriLike(descri);

        }

        if((type==null||type==null||type=="0")&&(descri==null||descri=="")){
            System.out.println("进入");
            costCountExample=null;
        }
        List<CostCount> costCounts = costCountMapper.selectByExample(costCountExample);
        return costCounts;
    }

    @Override
    public Integer insertCost(CostCount costCount) {
        int i = costCountMapper.insertSelective(costCount);
        return i;
    }
}
